package com.bwc.aidemo.http
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object ApiClients {

    private const val BASE_URL = "https://api.coze.cn/"
    val logging = HttpLoggingInterceptor().apply {
        level = HttpLoggingInterceptor.Level.BODY
    }
    // 创建自定义 OkHttpClient 来添加请求头
    private val client = OkHttpClient.Builder()
        .addInterceptor { chain ->
            val originalRequest: Request = chain.request()
            val newRequest: Request = originalRequest.newBuilder()
                .header("Authorization", "Bearer sat_bAFGMASZmif8dU59EnzwSUxuoB9ghj4wRuTepS3fzncOiJGccafcS0LM0QuIkgk2")
                .build()
            chain.proceed(newRequest)

        }
        .addInterceptor(logging)
        .build()

    // 创建 Retrofit 实例
    val retrofit: Retrofit = Retrofit.Builder()
        .baseUrl(BASE_URL)
        .client(client) // 使用自定义的 OkHttpClient
        .addConverterFactory(GsonConverterFactory.create()) // 使用Gson转换器
        .build()

    // 创建 ApiService 实例
    val apiService: ApiService = retrofit.create(ApiService::class.java)
}
